import 'package:flutter/material.dart';

class TextFiledCenterNoBorder extends StatelessWidget {
  TextEditingController controller;
  String? strHint;
  TextAlign textAlign;
  bool isObscureText;
  TextInputType? keyboardType;
  int maxLength = 30;
  TextInputAction textInputAction;
  double fontSize = 14;
  double leftPadding = 0;
  double rightPadding = 0;
  double hintFontSize = 14;
  int maxLines;
  Color? textColor;
  Color? hintTextColor;
  ValueChanged<String>? onChanged;
  final EdgeInsetsGeometry? contentPadding;
  FontWeight? fontWeight;

  TextFiledCenterNoBorder(this.controller,
      {super.key,
      this.strHint,
      this.textAlign = TextAlign.start,
      this.isObscureText = false,
      this.keyboardType,
      this.maxLength = 30,
      this.fontSize = 14,
      this.hintFontSize = 14,
      this.textInputAction = TextInputAction.done,
      this.leftPadding = 0,
      this.rightPadding = 0,
      this.maxLines = 1,
      this.textColor,
      this.hintTextColor,
      this.onChanged,
      this.contentPadding,
      this.fontWeight});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: leftPadding, right: rightPadding),
      child: TextField(
        controller: controller,
        onChanged: onChanged,
        textAlign: textAlign,
        /*
          确保textField内容能够完美居中的解决方案
          1.设置textField有边框，并设置外边框为透明色
          2.设置contentPadding:EdgeInsets.only(top: 0, bottom: 0)
       */
        decoration: InputDecoration(
          hintText: strHint,
          border: const OutlineInputBorder(
            borderSide: BorderSide(
              color: Colors.transparent,
            ),
          ),
          enabledBorder: const OutlineInputBorder(
            borderSide: BorderSide(
              color: Colors.transparent,
            ),
          ),
          disabledBorder: const OutlineInputBorder(
            borderSide: BorderSide(
              color: Colors.transparent,
            ),
          ),
          focusedBorder: const OutlineInputBorder(
            borderSide: BorderSide(
              color: Colors.transparent,
            ),
          ),
          contentPadding: contentPadding ?? const EdgeInsets.only(top: 0, bottom: 0),
          counterText: "",
          hintStyle: TextStyle(
            fontSize: hintFontSize,
            color: hintTextColor,
          ),
        ),
        maxLength: maxLength,
        style: TextStyle(
          fontSize: fontSize,
          color: textColor,
          fontWeight: fontWeight,
        ),
        keyboardType: keyboardType ?? TextInputType.text,
        obscureText: isObscureText,
      ),
    );
  }
}
